<template>
	<view>
		<view style="text-align: center;margin-top:50px;">
			<view style="font-size: 20px;">{{defaultData.title}} 课程签到二维码</view>
			<view style="margin-top:10px;">{{defaultData.attendClassTime}}</view>
			<view style="margin-top: 10px;">{{defaultData.quittingTime}}</view>
			<image :src="signInCode" style="margin-top:20px;"></image>
			<view style="margin-top:10px;color: blue;" @click="createQrCode"><uni-icons type="reload"
					style="color: blue;" size="20"></uni-icons>点击刷新二维码</view>
		</view>
	</view>
</template>
import {
getQRCode
} from '@/api/jz/info/sign.js'
<script>
	import {
		getQRCode
	} from '../../../../api/jz/sign/info';
	export default {
		data() {
			return {
				defaultData: {},
				signInCode: '',
				timer:null
			}
		},
		onLoad(val) {
			this.defaultData = JSON.parse(decodeURIComponent(val.data));
		},
		mounted() {
			this.createQrCode()
			this.timer = setInterval(() => {
				this.createQrCode()
			}, 30000) // 5s
		},
		onUnload() {if(this.timer) {  clearTimeout(this.timer);  this.timer = null;  }  
		},
		methods: {
			createQrCode() {
				let data = {
					classId: this.defaultData.classId,
					courseId: this.defaultData.id
				}
				getQRCode(data).then((res) => {
					if (res.code == 200) {
						this.signInCode = res.msg
					} else {
						console.log("系统错误")
					}
				})
			}
		}
	}
</script>

<style>

</style>